package com.team.auth.config.exception;

import com.team.common.base.DataResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//全局异常处理类
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler({SsoException.class})
    public Object hanlerDataException(SsoException e){
        log.error(e.getMessage(),e);
        SsoExceptionEnums ssoExceptionEnums = e.getSsoExceptionEnums();
        Object data = e.getData();
        if (data!=null){
            return new DataResult(ssoExceptionEnums.getCode(),ssoExceptionEnums.getMsg(),data);
        }else {
            return new DataResult(ssoExceptionEnums.getCode(),ssoExceptionEnums.getMsg());
        }
    }

}
